package net.dntuan.training.spring.mvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.provider.BaseClientDetails;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Just test response in json format
 * 
 * @author tuan.dang
 * 
 */
@Controller
@RequestMapping("public")
public class PublicInfoController {

    @Autowired
    private ClientDetailsService clientDetails;

    @RequestMapping("client")
    public ResponseEntity<ClientDetails> getClients(@RequestParam(value = "client_id") String clientId) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        return new ResponseEntity<ClientDetails>(clientDetails.loadClientByClientId(clientId), headers, HttpStatus.OK);
    }

    @RequestMapping("fixedclient")
    @ResponseBody
    public ClientDetails getFixedClient() {
        return new BaseClientDetails("application_client", "oauth_resource_id", "read", "password", "ROLE_APP_CLIENT");
    }
}
